<?php
session_start();
if($_SESSION["islogin"]!=='igiveyouthepower'){
echo "<script language=JavaScript>\r\n";
echo "alert('请先登录!');\r\n";
echo "location.href='index.php'\r\n";
echo "</script>";
}else{
require_once('config.php');
?>
<?php
$conn = mysqli_connect($cfg_dbhost,$cfg_dbuser,$cfg_dbpwd,$cfg_dbname);
$mquery="select * from ph_admin where admin='".$_SESSION["managername"]."'";
$mresult=mysqli_query($conn,$mquery);
$rowuser = mysqli_fetch_array($mresult);

 // 获取文件夹大小
 function getDirSize($dir)
 { 
  $handle = opendir($dir);
  while (false!==($FolderOrFile = readdir($handle)))
  { 
   if($FolderOrFile != "." && $FolderOrFile != "..") 
   { 
    if(is_dir("$dir/$FolderOrFile"))
    { 
     $sizeResult += getDirSize("$dir/$FolderOrFile"); 
    }
    else
    { 
     $sizeResult += filesize("$dir/$FolderOrFile"); 
    }
   } 
  }
  closedir($handle);
  return $sizeResult;
 }
 // 单位自动转换函数
 function getRealSize($size)
 { 
  $kb = 1024;   // Kilobyte
  return round($size/$kb,2);
 }
 //echo getRealSize(getDirSize($_SERVER['DOCUMENT_ROOT'].'/files/1'));
$realsize=getRealSize(getDirSize($_SERVER['DOCUMENT_ROOT'].'/files/'.$rowuser["ID"]));
$sql = "update ph_admin set currenthostsize='".$realsize."' where id='".$rowuser["ID"]."'";
mysqli_query($conn,$sql);
echo "<script language=JavaScript>\r\n";
echo "location.href='/main.php'\r\n";
echo "</script>";
}
?>